import { craeteEffect, effectTypes } from './helper'

/**
 * 提供一个函数，用于得到当前仓库中的数据
 * @param {*} fun
 * @return {*} 
 */
export function select(fun) {
    return craeteEffect(effectTypes.SELECT, { fun })
}

/**
 * 处理 select effect 
 * @export
 * @param {*} env
 * @param {*} effect
 * @param {*} next
 */
export function runSelectEffect(env, effect, next) {
    const { store } = env
    const { payload: { fun } } = effect
    let state = store.getState()
    if (fun && typeof fun === 'function') {
        state = fun(state)
    }
    next(state)
}